package com.fjnu.controller;

import com.fjnu.uitl.ResponseResult;
import com.fjnu.entity.Tag;
import com.fjnu.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("tag")
public class TagController {
    @Autowired
    private TagService tagService;
    @GetMapping("list")
    public ResponseResult list(){
        List<Tag> list = tagService.list();
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("查询成功");
        responseResult.setData(list);
        return responseResult;
    }
    @GetMapping("delete")
    public ResponseResult deleteTag(Integer tagId){
        int i = tagService.delete(tagId);
        ResponseResult responseResult = new ResponseResult();
        if (i > 0){
            responseResult.setCode("200");
            responseResult.setMessage("删除成功");
        }
        else{
            responseResult.setCode("500");
            responseResult.setMessage("删除失败");
        }
        return responseResult;
    }
    @PostMapping("add")
    public ResponseResult addTag(Tag tag){
        int i = tagService.add(tag);
        ResponseResult responseResult = new ResponseResult();
        if (i > 0){
            responseResult.setCode("200");
            responseResult.setMessage("添加成功");
        }
        else{
            responseResult.setCode("500");
            responseResult.setMessage("添加失败");
        }
        return responseResult;
    }

}
